/**
 * 
 */
package com.google.code.onlineshopping4j.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author TelmilaJ
 *
 */
@Controller
public class LoginController {
	
	public static final String LOGIN_REQUEST_MAPPING = "/login";
	public static final String LOGINFAILED_REQUEST_MAPPING = "/loginfailed";
	public static final String LOGOUT_REQUEST_MAPPING = "/logout";
	
	public static final String LOGIN_VIEW_NAME = "login"; 
	@RequestMapping(value = LOGIN_REQUEST_MAPPING, method = RequestMethod.GET)
	public String login(ModelMap model) {
 		return LOGIN_VIEW_NAME;
 	}
 
	@RequestMapping(value = LOGINFAILED_REQUEST_MAPPING, method = RequestMethod.GET)
	public String loginerror(ModelMap model) {
		model.addAttribute("error", "true");
		return LOGIN_VIEW_NAME;
	}
 
	@RequestMapping(value = LOGOUT_REQUEST_MAPPING, method = RequestMethod.GET)
	public String logout(ModelMap model, HttpSession session) {
		session.invalidate();
		return LOGIN_VIEW_NAME;
	}
}
